//
//  ViewController.m
//  textfiled格式化
//
//  Created by iOS on 16/6/15.
//  Copyright © 2016年 iOS. All rights reserved.
//

#import "ViewController.h"
#import "ZJTextfieldView.h"
#import "TableViewController.h"
@interface ViewController ()<UITextFieldDelegate>
@property (nonatomic,strong)UITextField * Mytextfield;
@property (nonatomic,strong)ZJTextfieldView * zjtext;
@property (nonatomic,strong)ZJTextfieldView * phone;
@property (nonatomic,strong)ZJTextfieldView * tableList;
@property (nonatomic,strong)ZJTextfieldView * account;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ZJTextfieldView * tfv = [[ZJTextfieldView alloc]initWithFrame:CGRectMake(50, 50, 300, 50)];
    tfv.ZJtextfield.borderStyle = UITextBorderStyleRoundedRect;
    tfv.ZJTextfieldStyle = ZJTextfieldStyleBank;
    tfv.ZJtextfield.placeholder = @"银 行  ZJTextfieldStyleBank";
    tfv.ZJtextfield.delegate = self;
    [self.view addSubview:tfv];
    
    self.zjtext = tfv;

    
    UIView * subView = [[UIView alloc]initWithFrame:CGRectMake(0, 600, 400, 55)];
    subView.backgroundColor = [UIColor redColor];
    [self.view addSubview:subView];

    
    ZJTextfieldView * phonetext = [[ZJTextfieldView alloc]initWithFrame:CGRectMake(50, 3, 300, 50)];
   //  ZJTextfieldView * phonetext = [[ZJTextfieldView alloc]initWithFrame:CGRectMake(50, 600, 300, 50)];
    phonetext.ZJtextfield.borderStyle = UITextBorderStyleRoundedRect;
    phonetext.ZJTextfieldStyle = ZJTextfieldStylePhone;
    phonetext.ZJtextfield.placeholder = @"手 机 ZJTextfieldStylePhone";
    phonetext.ZJtextfield.delegate = self;
    [subView addSubview:phonetext];
    
    self.phone = phonetext;
    
    
    
    
    
    ZJTextfieldView * tablelist = [[ZJTextfieldView alloc]initWithFrame:CGRectMake(50, 500, 300, 50)];
    tablelist.ZJtextfield.borderStyle = UITextBorderStyleRoundedRect;
    tablelist.ZJTextfieldStyle = ZJTextfieldStyleNone;
    tablelist.ZJtextfield.placeholder = @"列表 ZJTextfieldStyleTableList";
    tablelist.talbeListArray = [NSMutableArray arrayWithArray:@[@"wewe",@"sdsdsd",@"sdsdsd"]];
    tablelist.ZJtextfield.delegate = self;
    [self.view addSubview:tablelist];
    
    self.tableList = tablelist;

    ZJTextfieldView * Account = [[ZJTextfieldView alloc]initWithFrame:CGRectMake(50, 400, 300, 50)];
    Account.ZJtextfield.borderStyle = UITextBorderStyleRoundedRect;
    Account.ZJTextfieldStyle = ZJTextFieldStyleAccount;
    Account.ZJtextfield.placeholder = @"账号  ZJTextFieldStyleAccount";
   // Account.talbeListArray = [NSMutableArray arrayWithArray:@[@"wewe",@"sdsdsd",@"sdsdsd"]];
    Account.ZJtextfield.delegate = self;
    [self.view addSubview:Account];
    
    self.account = Account;
    // Do any additional setup after loading the view, typically from a nib.
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
 
    if (textField == self.zjtext.ZJtextfield) {
        [self.zjtext ZJtextFieldCreateTableviewDidBeginEditing:textField];
    }else if (textField == self.phone.ZJtextfield) {
        [self.phone ZJtextFieldCreateTableviewDidBeginEditing:textField];
    }else if (textField == self.tableList.ZJtextfield) {
        [self.tableList ZJtextFieldCreateTableviewDidBeginEditing:textField];
    }else if (textField == self.account.ZJtextfield) {
        [self.account ZJtextFieldCreateTableviewDidBeginEditing:textField];
    }


}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField == self.zjtext.ZJtextfield) {
        [self.zjtext ZJtextFieldWriteTextDidEndEditing:self.zjtext.ZJtextfield];
    }else if (textField == self.phone.ZJtextfield) {
        [self.phone ZJtextFieldWriteTextDidEndEditing:self.phone.ZJtextfield];
    }else if (textField == self.tableList.ZJtextfield) {
        [self.tableList ZJtextFieldWriteTextDidEndEditing:self.tableList.ZJtextfield];
    }else if (textField == self.account.ZJtextfield) {
        [self.account ZJtextFieldWriteTextDidEndEditing:self.account.ZJtextfield];
    }


}



- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    if (textField == self.zjtext.ZJtextfield) {
        return [self.zjtext ZJtextField:textField shouldChangeCharactersInRange:range replacementString:string];
    }else if (textField == self.phone.ZJtextfield) {
        return [self.phone ZJtextField:textField shouldChangeCharactersInRange:range replacementString:string];
    }else if (textField == self.tableList.ZJtextfield) {
        return [self.tableList ZJtextField:textField shouldChangeCharactersInRange:range replacementString:string];
    }else if (textField == self.account.ZJtextfield) {
        return [self.account ZJtextField:textField shouldChangeCharactersInRange:range replacementString:string];
    }

    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (textField == self.zjtext.ZJtextfield) {
        return [self.zjtext ZJtextFieldShouldReturn:textField];
    }else if (textField == self.phone.ZJtextfield) {
        return [self.phone ZJtextFieldShouldReturn:textField];
    }else if (textField == self.tableList.ZJtextfield) {
        return [self.tableList ZJtextFieldShouldReturn:textField];
    }else if (textField == self.account.ZJtextfield) {
        return [self.account ZJtextFieldShouldReturn:textField];
    }
   

    return YES;}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
    
    TableViewController * tab = [[TableViewController alloc]init];
    [self presentViewController:tab animated:YES completion:nil];
  //  NSLog(@"aaaa==%@",self.zjtext.ZJtext);
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
